#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <pthread.h>


//简单同步问题
//投篮和传球·

pthread_cond_t g_cond;//条件变量
pthread_mutex_t mutex;//互斥量

void * Entry_1(void * arg)
{
  (void )arg;
  while(1)
  {
    pthread_cond_wait(&g_cond,&mutex);//等待投篮的人
    printf("传球\n");
    sleep(1);
  }
  return NULL;
}

void * Entry_2(void * arg)
{
  (void )arg;
  while(1)
  {
    printf("投篮\n");
    sleep(1);
    pthread_cond_signal(&g_cond);
  }
  return NULL;
}


void test()
{
  pthread_mutex_init(&mutex,NULL);
  pthread_cond_init(&g_cond,NULL);


  pthread_t thread_1,thread_2;
  pthread_create(&thread_1,NULL,Entry_1,NULL);
  pthread_create(&thread_2,NULL,Entry_2,NULL);


  pthread_join(thread_1,NULL);
  pthread_join(thread_2,NULL);
  pthread_mutex_destroy(&mutex);
  pthread_cond_destroy(&g_cond);
}

int main()
{

  test();
  return 0;
}
